<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="./vue.js"></script>
</head>
<body>

<div id="app">
    <!-- 因为组件的命名方式为驼峰，因此此处要用下划线 -->
    <a href="" @click.prevent="currentComponent='my-component'">切换第一个组件</a>
    <a href="" @click.prevent="currentComponent='gagaga'">切换第二个组件</a>
    <component :is="currentComponent"></component>

</div>

<template id="balala">
    <div>
        <h3>劲夫劲夫，女人痛苦</h3>
        <h1>{{message}}</h1>
    </div>
</template>
<script>


    var vm = new Vue({
        el:"#app",
        data:{
            currentComponent:"my-component",
        },
        //定义实例内部的私有组件
        components:{
            "my-component":{
                template: '<h1>吧啦啦啦啦</h1>',
                created:function(){
                    console.log('组件1已经创建')
                },
                destroyed(){
                    console.log('组件1已经被摧毁')
                }
            },
            //组件名称：gagaga,模板:balala
            gagaga:{
                template:"#balala",
                data:function () {
                    return {
                        message: "组件的data必须是function，且该function必须返回一个对象"
                    }
                },
                created:function(){
                    console.log("组件2已经创建")
                },
                destroyed(){
                    console.log('组件2已经被摧毁')
                }
            }
        }
    })
</script>
</body>
</html>